package com.example.design.结构型设计模式.组合模式;

// 菜单项，即叶子节点、叶子组件
public record MenuItem(String name, double price) implements MenuComponent {

    @Override
    public void print() {
        System.out.println("MenuItem: " + name() + ", Price: $" + price());
    }

    // 单个菜品不支持添加或移除子组件
    @Override
    public void add(MenuComponent menuComponent) {
        throw new UnsupportedOperationException("Cannot add to a MenuItem");
    }

    @Override
    public void remove(MenuComponent menuComponent) {
        throw new UnsupportedOperationException("Cannot remove from a MenuItem");
    }
}
